package org.hit.burkun.calc;


import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;

import org.hit.burkun.db.DBHelper;
import org.hit.burkun.db.DBTypeConverter;
import org.hit.burkun.model.Content;
import org.hit.burkun.utils.StaticMethods;

public class MidSim {

	public static void main(String[] args) {
	
		double threadHold = 0.3;
		int maxCounter = 10000;
		DBHelper dbh = DBHelper.getServerDataDBHelper();
		dbh.connectionDB();
		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[5];
		types[2] = DBTypeConverter.DATATYPE.D;
		DBTypeConverter typeConverter = new DBTypeConverter(types);
		HashSet<String> set = new HashSet<>();
		String[] fileds = new String[]{"mid1", "mid2", "score"};
		Collection<Content> finalRes = StaticMethods.getMid2ContentTrain().values();
		LinkedList<String[]> ress = new LinkedList<String[]>();
		int counter1 = 0;
		for(Content c1 : finalRes){
			counter1 ++;
			int counter2 = 0;
			set.add(c1.getMid());
			for(Content c2 : finalRes){
				counter2 ++;
				System.out.println(counter1 + " : " + counter2);
				if(!set.contains(c2.getMid())){
					double score = Content.getEditSim(c1, c2);
					if(score > threadHold){
						String[] line = new String[3];
						if(c1.getMid().compareTo(c2.getMid()) > 0){
							line[0] = c2.getMid();
							line[1] = c1.getMid();
						}else{
							line[1] = c1.getMid();
							line[0] = c2.getMid();
						}
						line[2] = Double.toString(score);
						ress.add(line);
						if(ress.size() == maxCounter){
							dbh.insertBatch("train_mid_sim", fileds, ress, typeConverter);
							ress.clear();
							System.out.println("10000 done!");
						}
					}
				}
			}
		}
		dbh.disconnection();
	}

}
